<?php

class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
{
    public function _initDoctrine()
    {
        // Connect
        $config = new Zend_Config_Ini(
            APPLICATION_PATH . '/configs/database.ini',
            $this->getEnvironment()
        );
        $dsn = $config->type . '://'
            .  $config->username . ':'
            .  $config->password . '@'
            .  $config->host . '/'
            .  $config->dbname;

        Doctrine_Manager::connection($dsn, $config->name);

        $doctrine = Doctrine_Manager::getInstance();
        $doctrine->setAttribute(Doctrine::ATTR_AUTOLOAD_TABLE_CLASSES, true);
        $doctrine->setAttribute(Doctrine::ATTR_MODEL_LOADING, Doctrine::MODEL_LOADING_AGGRESSIVE);

        $modelsDirectory     = $this->getApplication()->getOption('modelsdirectory');
        $baseModelsDirectory = $modelsDirectory . DIRECTORY_SEPARATOR . '/generated';

        foreach (new DirectoryIterator($baseModelsDirectory) as $baseModel) {
            if ($baseModel->isFile()) {
                include_once($baseModel);
            }
        }
        Doctrine::loadModels($modelsDirectory);
    }

    public function _initServices()
    {
    }
}

